using KnowledgeQA.Models.DTOs;

namespace KnowledgeQA.Core.Interfaces
{
    /// <summary>
    /// AI服务接口
    /// </summary>
    public interface IAIService
    {
        /// <summary>
        /// 模型名称
        /// </summary>
        string ModelName { get; }

        /// <summary>
        /// 生成回答
        /// </summary>
        /// <param name="prompt">提示词</param>
        /// <param name="context">上下文</param>
        /// <param name="parameters">模型参数</param>
        /// <returns>AI回答</returns>
        Task<AIResponse> GenerateAnswerAsync(string prompt, string? context = null, Dictionary<string, object>? parameters = null);

        /// <summary>
        /// 生成向量嵌入
        /// </summary>
        /// <param name="text">文本内容</param>
        /// <returns>向量数据</returns>
        Task<float[]> GenerateEmbeddingAsync(string text);

        /// <summary>
        /// 批量生成向量嵌入
        /// </summary>
        /// <param name="texts">文本列表</param>
        /// <returns>向量数据列表</returns>
        Task<float[][]> GenerateEmbeddingsAsync(IEnumerable<string> texts);

        /// <summary>
        /// 计算文本相似度
        /// </summary>
        /// <param name="text1">文本1</param>
        /// <param name="text2">文本2</param>
        /// <returns>相似度分数</returns>
        Task<double> CalculateSimilarityAsync(string text1, string text2);

        /// <summary>
        /// 检查服务是否可用
        /// </summary>
        /// <returns>是否可用</returns>
        Task<bool> IsAvailableAsync();
    }

    /// <summary>
    /// AI响应
    /// </summary>
    public class AIResponse
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 回答内容
        /// </summary>
        public string Content { get; set; } = string.Empty;

        /// <summary>
        /// 使用的令牌数
        /// </summary>
        public int TokensUsed { get; set; }

        /// <summary>
        /// 处理时间（毫秒）
        /// </summary>
        public long ProcessingTime { get; set; }

        /// <summary>
        /// 置信度评分
        /// </summary>
        public double ConfidenceScore { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string? ErrorMessage { get; set; }

        /// <summary>
        /// 元数据
        /// </summary>
        public Dictionary<string, object> Metadata { get; set; } = new Dictionary<string, object>();
    }
} 